package com.tanhua.server.controller;

import com.tanhua.server.service.BaiduService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Map;

/**
 * @description:
 * @author: Administrator
 * @date: Created in 2021/2/28 16:09
 * @version: 0.0.1
 * @modified By:1
 */
@RestController
@RequestMapping("baidu")
public class BaiduController {

    @Autowired
    private BaiduService baiduService;
    /**
     * @description 更新位置
     * @author
     * @date
     * @param
     *@return
     */
    @PostMapping("location")
    public ResponseEntity<Void>updateLocation(@RequestBody Map<String,Object>param){
        try {
            Double latitude = Double.valueOf(param.get("latitude").toString());
            Double longitude=Double.valueOf(param.get("longitude").toString());
            String addrStr=param.get("addrStr").toString();
            Boolean bool= this.baiduService.updateUserLocation(longitude,latitude,addrStr);
            if(bool){
                return ResponseEntity.ok(null);
            }
        } catch (NumberFormatException e) {
            e.printStackTrace();
        }
        return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR).build();
    }
}
